from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
import pandas as pd

from domain.default_news import news_data

if __name__ == '__main__':
    engine = create_engine('sqlite:///database/news.db')
    Session = sessionmaker(bind=engine)
    session = Session()
    excel = pd.read_excel("data/期刊文摘.xlsx")
    type_list = excel["分类"].tolist()
    text_list = excel["正文"].tolist()
    for i in range(len(type_list)):
        add_new = news_data(type=type_list[i],text=text_list[i], id=i+1)
        session.add(add_new)
    session.commit()
    session.close()